package com.cpkso.yzx.web;

import java.io.File;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cpkso.yzx.domain.Col;
import com.cpkso.yzx.domain.News;
import com.cpkso.yzx.service.ColService;

import runze.util.base.BaseAction;
import runze.util.base.Response;

/**
 * @author wrzhxy@qq.com
 * @date 2017年11月10日
 */
@SuppressWarnings({"serial", "unused"})
@Controller
@Scope("prototype")
public class ColAction extends BaseAction<Object> {
	public String findByCol() {
		response = colService.findByCol(col.getUrlcode());
		return SUCCESS;
	}
	public String single() {
		response = colService.get(news.getId());
		return SUCCESS;
	}
	public String list() {
		response = colService.list();
		return SUCCESS;
	}
	public String modifyCol() {
		colService.modifyCol(col);
		return SUCCESS;
	}
	public String addNews() {
		String pic_path = ServletActionContext.getServletContext().getRealPath("/uploads/");
		long add = 0;
		try {
			add = colService.addNews(news, picFileName, pic, "D:/snowpics/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (add == 0) {
			response.failure();
		}
		return SUCCESS;
	}
	public String delNews() {
		colService.delNews(news.getId());;
		return SUCCESS;
	}
	public String modifyNews() {
		String pic_path = ServletActionContext.getServletContext().getRealPath("/uploads/");
		colService.modifyNews(news, picFileName, pic, "D:/snowpics/");
		return SUCCESS;
	}
	
	/**
	 * 富文本编辑器处理多张图片
	 */
	public String uploadMultiPics() {
		String path = ServletActionContext.getServletContext().getRealPath("/uploads/");
		response = colService.uploadMultiPics(file, fileFileName, "D:/snowpics/");
		
		return SUCCESS;
	}
	private File[] file;
	private String[] fileContentType;
	private String[] fileFileName;
	public void setFile(File[] file) {
		this.file = file;
	}
	public void setFileContentType(String[] fileContentType) {
		this.fileContentType = fileContentType;
	}
	public void setFileFileName(String[] fileFileName) {
		this.fileFileName = fileFileName;
	}

	private File pic;
	private String picContentType;
	private String picFileName;
	public void setPic(File pic) {
		this.pic = pic;
	}
	public void setPicContentType(String picContentType) {
		this.picContentType = picContentType;
	}
	public void setPicFileName(String picFileName) {
		this.picFileName = picFileName;
	}
	private Col col;
	private News news;
	public Col getCol() {
		return col;
	}
	public void setCol(Col col) {
		this.col = col;
	}
	public News getNews() {
		return news;
	}
	public void setNews(News news) {
		this.news = news;
	}
	private Response response = new Response();
	public Response getResponse() {
		return response;
	}
	@Autowired
	private ColService colService;
}
